﻿using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace MvcToolbox.Test
{
    [TestFixture]
    public class EnsureTest
    {
        #region That

        [Test]
        public void Ensure_That_Test()
        {
            Ensure.That(3 > 2, "3 is not > 2");
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void Ensure_That_Exception_Test()
        {
            Ensure.That(3 > 4, "3 is not > 2");
        }

        [Test]
        public void Ensure_That_WithTypeException_Test()
        {
            Ensure.That<ArgumentException>(3 > 2, "3 is not > 2");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void Ensure_That_WithTypeException_Exception_Test()
        {
            Ensure.That<ArgumentException>(3 > 4, "3 is not > 2");
        }

        #endregion

        #region Not

        [Test]
        public void Ensure_Not_Test()
        {
            Ensure.Not(3 < 2, "3 is not < 2");
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void Ensure_Not_Exception_Test()
        {
            Ensure.Not(3 < 4, "3 is not < 2");
        }

        [Test]
        public void Ensure_Not_WithTypeException_Test()
        {
            Ensure.Not<ArgumentException>(3 < 2, "3 is not < 2");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void Ensure_Not_WithTypeException_Exception_Test()
        {
            Ensure.Not<ArgumentException>(3 < 4, "3 is not < 2");
        }

        #endregion

        #region NotNull

        [Test]
        public void Ensure_NotNull_Test()
        {
            string t = "ok";
            Ensure.NotNull(t, "t is null");
        }

        [Test]
        [ExpectedException(typeof(NullReferenceException))]
        public void Ensure_NotNull_Exception_Test()
        {
            string t = null;
            Ensure.NotNull(t, "t is null");
        }

        #endregion

        #region Equals

        [Test]
        public void Ensure_Equal_Test()
        {
            string t = "ok";
            string t1 = "ok";
            Ensure.Equal(t, t1);
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void Ensure_Equal_Exception_Test()
        {
            string t = "ok";
            string t1 = "ok1";
            Ensure.Equal(t, t1);
        }

        [Test]
        public void Ensure_Equal_Message_Test()
        {
            string t = "ok";
            string t1 = "ok";
            Ensure.Equal(t, t1, "t != t1");
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void Ensure_Equal_Message_Exception_Test()
        {
            string t = "ok";
            string t1 = "ok1";
            Ensure.Equal(t, t1, "t != t1");
        }

        #endregion

        #region NotEquals

        [Test]
        public void Ensure_NotEqual_Test()
        {
            string t = "ok";
            string t1 = "ok1";
            Ensure.NotEqual(t, t1);
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void Ensure_NotEqual_Exception_Test()
        {
            string t = "ok";
            string t1 = "ok";
            Ensure.NotEqual(t, t1);
        }

        #endregion

        #region Contains

        [Test]
        public void Ensure_Contains_Test()
        {
            List<string> t = new List<string>();
            t.Add("ok");
            t.Add("ok1");
            Ensure.Contains(t, (item) => item == "ok");
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void Ensure_Contain_Exceptions_Test()
        {
            List<string> t = new List<string>();
            t.Add("ok");
            t.Add("ok1");
            Ensure.Contains(t, (item) => item == "ok2");
        }

        #endregion

        #region Items

        [Test]
        public void Ensure_Items_Test()
        {
            List<string> t = new List<string>();
            t.Add("ok");
            t.Add("ok1");
            Ensure.Items(t, (item) => item.StartsWith("ok"));
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void Ensure_Items_Exceptions_Test()
        {
            List<string> t = new List<string>();
            t.Add("ok");
            t.Add("ok1");
            Ensure.Items(t, (item) => item.StartsWith("ok1"));
        }

        #endregion

        #region NotNullOrEmpty

        [Test]
        public void Ensure_NotNullOrEmpty_Test()
        {
            string t = "ok";
            Ensure.NotNullOrEmpty(t, "t is null");
        }

        [Test]
        [ExpectedException(typeof(Exception))]
        public void Ensure_NotNullOrEmpty_Exception_Test()
        {
            string t = string.Empty;
            Ensure.NotNullOrEmpty(t, "t is null");
        }

        #endregion

        #region Is

        [Test]
        public void EnsureArgument_Is_Test()
        {
            Ensure.Argument.Is(1 == 1, "No message");
        }


        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void EnsureArgument_Is_Exception_Test()
        {
            Ensure.Argument.Is(1 == 2, "No message");
        }

        #endregion

        #region IsNot

        [Test]
        public void EnsureArgument_IsNot_Test()
        {
            Ensure.Argument.IsNot(1 == 2, "No message");
        }


        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void EnsureArgument_IsNot_Exception_Test()
        {
            Ensure.Argument.IsNot(1 == 1, "No message");
        }

        #endregion

        #region NotNull

        [Test]
        public void EnsureArgument_NotNull_Test()
        {
            string t = "ok";
            Ensure.Argument.NotNull(t, "No message");
        }


        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void EnsureArgument_NotNull_Exception_Test()
        {
            string t = null;
            Ensure.Argument.NotNull(t, "No message");
        }

        #endregion

        #region NotNullOrEmpty

        [Test]
        public void EnsureArgument_NotNullOrEmpty_Test()
        {
            string t = "ok";
            Ensure.Argument.NotNullOrEmpty(t, "No message");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void EnsureArgument_NotNullOrEmpty_Null_Exception_Test()
        {
            string t = null;
            Ensure.Argument.NotNullOrEmpty(t, "No message");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void EnsureArgument_NotNullOrEmpty_Empty_Exception_Test()
        {
            string t = string.Empty;
            Ensure.Argument.NotNullOrEmpty(t, "No message");
        }


        [Test]
        public void EnsureArgument_NotNullOrEmpty_NoMsg_Test()
        {
            string t = "ok";
            Ensure.Argument.NotNullOrEmpty(t);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void EnsureArgument_NotNullOrEmpty_Null_Exception_NoMsg_Test()
        {
            string t = null;
            Ensure.Argument.NotNullOrEmpty(t);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void EnsureArgument_NotNullOrEmpty_Empty_Exception_NoMsg_Test()
        {
            string t = string.Empty;
            Ensure.Argument.NotNullOrEmpty(t);
        }

        #endregion
    }
}
